package com.danny.demo.entity;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

/**
 * @ClassName: ScannerAndBufferReader
 * @Description: 键盘输入两种实现方式
 * @Author: zhangdong
 * @Date: Created in 14:29 2019/6/19
 * @Version:
 */
public class ScannerAndBufferReader {

    public static void main(String[] args) throws IOException {
        ScannerAndBufferReader scannerAndBufferReader = new ScannerAndBufferReader();
        //scannerAndBufferReader.ScannerMethod();
        scannerAndBufferReader.BufferReaderMethod();

    }
    public void ScannerMethod(){
        //方法1.通过Scanner
        System.out.println("请输入编号：1、喜欢 2、不喜欢");
        Scanner input = new Scanner(System.in);
        String s = input.nextLine();

        if (s.equals("1")){
            System.out.println("我也喜欢");
        }else if(s.equals("2")){
            System.out.println("我也不喜欢");
        }
        input.close();
    }
    public void BufferReaderMethod() throws IOException {
        //2.通过BufferedReader
        System.out.println("请输入编号：1、喜欢 2、不喜欢");
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        String s = input.readLine();
        if (s.equals("1")){
            System.out.println("我也喜欢");
        }else if(s.equals("2")){
            System.out.println("我也不喜欢");
        }
        input.close();
    }
}
